/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.pdx.cs.guavalib;

import edu.pdx.cs.guavadata.AppData;
import edu.pdx.cs.guavadata.Guava;
import edu.pdx.cs.guavadata.domain.Domain;
import edu.pdx.cs.guavadata.subclass.ControlType;
import edu.pdx.cs.guavadata.subclass.DataTable;
import edu.pdx.cs.guavadata.subclass.LaunchType;
import java.awt.Dimension;
import java.awt.Point;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 *
 * @author VuTran
 */
public class GJTextField extends JTextField implements Guava {

    String gname;
    boolean isQmode;
    JLabel lab;
    
    public GJTextField() {
        super();
        this.isQmode = false;
    }

    public GJTextField(boolean mode) {
        this();
        this.isQmode = mode;
    }

    public JLabel getLabel() {
        return lab;
    }

    public void setLabel(JLabel label) {
        this.lab = label;
    }

    public LaunchType getLType() {
        return LaunchType.NA;
    }

    public ControlType getCType() {
        return ControlType.Attribute;
    }

    public String getGText() {
        if (this.lab == null) {
            return null;
        }
        return this.lab.getText();
    }

    public String getGName() {
        if (gname == null)
            return this.getName();
        return gname;
    }

    public void setGName(String GName) {
       this.gname = GName;
    }

    public Point getGLocation() {
        return this.getLocation();
    }

    public Dimension getGSize() {
        return this.getSize();
    }

    public List<Guava> getGComponents() {
        return new ArrayList<Guava>();
    }

    public void gBind(String table, int i) {
        DataTable dt = AppData.ds.getTable(table);
        if (!dt.rows.isEmpty()) {
            dt.rows.get(i).put(this.getGName(), this.getText());
        }
    }

    public void gBindFromDatabase(String table, int i) {
        DataTable dt = AppData.ds.getTable(table);
        if (!dt.rows.isEmpty()) {
            if (dt.rows.get(i).get(this.getGName()) != null) {
                this.setText(dt.rows.get(i).get(this.getGName()).toString());
            }
        }
    }

    public String getGDefault() {
        return this.getText();
    }

    public String getGToolTip() {
        return this.getToolTipText();
    }

    public Domain getGDomain() {
        return new edu.pdx.cs.guavadata.domain.String(100);
    }

    public Guava get(String s) {
        for (Guava g : this.getGComponents())
            if (g.getGName().equals(s))
                return g;
        return null;
    }

}
